package com.itheima.publisher.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@Slf4j
public class PublisherController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 测试消息发送
     */
    @GetMapping
    public void testSendMsg() {
        rabbitTemplate.convertAndSend("simple.queue", "你好，我是小小开发者。");
    }


    /**
     * 测试消息发送
     */
    @GetMapping("send")
    public void testSendMsg2() {
        for (int i = 0; i <= 50; i++) {
            rabbitTemplate.convertAndSend("work.queue", "你好，我是小小开发者。" + i);
        }
    }

    /**
     * 测试fanout队列发送消息
     */
    @GetMapping("sendFanout")
    public void testSendMsg1() {
        // 交换机名称
        String exchangeName = "hmall.fanout";
        rabbitTemplate.convertAndSend(exchangeName,null, "你好，我是小小开发者。");
    }

}
